<?php

declare(strict_types=1);

namespace App\JsonRpc\Service;

use App\JsonRpc\RpcOrderServiceInterface;
use Hyperf\DbConnection\Db;
use Hyperf\RpcServer\Annotation\RpcService;

use function Hyperf\Config\config;

#[RpcService(name: 'RpcOrderService', publishTo: 'nacos')]
class RpcOrderService implements RpcOrderServiceInterface
{
    public function createTest(): int
    {
        $id = mt_rand(1111, 9999);
        Db::table('test')->where('id', 1)->update(['name' => date('Y-m-d H:i:s', time())]);

        return $id;
    }

    public function createTestError(): mixed
    {
        $nacos_config_test = config('nacos_config.test', false);
        if ($nacos_config_test) {
            throw new \Exception('Error Processing Request', 1);
        }

        return __CLASS__;
    }
}
